/**
 * Copyright (C) 2011, mordredd666 [_at_] gmail.com
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package de.mordred.gui;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import de.mordred.Main;

public class TopLeiste extends JPanel
{

	private static final long serialVersionUID = 4153264593318448160L;

	private JButton _previous;
	private JLabel _centerLabel;
	private JButton _next;

	/**
	 * Erstellt eine Topleiste mit Link zum Hauptmenü
	 */
	public TopLeiste()
	{

		this.setLayout(new BorderLayout());
		addHauptmenu();
	}

	/**
	 * Erstellt eine Topleiste mit Link zum Hauptmenü und Titel
	 * 
	 * @param titel
	 */
	public TopLeiste(String titel)
	{
		this();
		_centerLabel = new JLabel(titel);
		this.add(_centerLabel, BorderLayout.CENTER);
	}

	public TopLeiste(FixedPanel lastpanel, String titel, FixedPanel nextpanel)
	{

		if (lastpanel == null)
		{
			addHauptmenu();
		}
		else
		{
			_previous = new JButton(lastpanel.getTitel());
			_previous.addActionListener(getActionlistener(lastpanel));
			this.add(_previous, BorderLayout.WEST);
		}

		if (titel != null)
		{

			_centerLabel = new JLabel(titel);
			_centerLabel.setAlignmentX(JLabel.RIGHT_ALIGNMENT);
			this.add(_centerLabel, BorderLayout.CENTER);
		}
		else
		{
			_centerLabel = new JLabel();
			this.add(_centerLabel, BorderLayout.CENTER);
		}

		if (nextpanel != null)
		{
			_next = new JButton(nextpanel.getTitel());
			_next.addActionListener(getActionlistener(nextpanel));
			this.add(_next, BorderLayout.EAST);
		}
	}

	/**
	 * Topleiste nur mit Hauptmenü ohne titel
	 */
	private void addHauptmenu()
	{
		_previous = new JButton("Hauptmenü");
		this.add(_previous, BorderLayout.WEST);
		_previous.addActionListener(getActionlistener(new SelectionScreen()));
	}

	private ActionListener getActionlistener(final FixedPanel panel)
	{
		return new ActionListener()
		{

			@Override
			public void actionPerformed(ActionEvent e)
			{
				Main.setNextPanel(panel);

			}
		};
	}

	/**
	 * Linker Button
	 * 
	 * @return
	 */
	public JButton getPrevious()
	{
		return _previous;
	}

	/**
	 * Rechter Button
	 * 
	 * @return
	 */
	public JButton getNext()
	{
		return _next;
	}

	/**
	 * Titel
	 * 
	 * @return
	 */
	public JLabel getText()
	{
		return _centerLabel;
	}
}
